package com.ato.Thread;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author wangjing
 * @create 2021--09--25--21:18
 */
public class TreadPool {
    public static void main(String[] args) {
//       1: 创建固定多少个线程的线程池
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        /** 注意：executorService返回的实际是接口，多态。   那么就强转
                 ThreadPoolExecutor tpe = (ThreadPoolExecutor) executorService;
                 tpe.setKeepAliveTime( );  活跃时间：线程保持多久时间终止
                 tpe.setCorePoolSize(); 核心池大小
                 tpe.setMaximumPoolSize(); 最大连接数
         */
//        executorService.submit();// 适用于Callable
//        executorService.execute();// 使用与 Runable

        executorService.execute(new Fore());// 2:这里可以有多个线程执行，

        executorService.shutdown();//3: 关闭线程池
    }
}

class Fore implements Runnable {

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "创建成功");
    }
}



